package
{
	import mx.collections.ArrayList;
	import mx.containers.Accordion;
	import mx.containers.Canvas;
	/**
	 * Class Manager Class
	 * 
	 * Manages classes up to 6
	 * TODO: for now, we manually initialize classes. Fix this later
	 * 
	 * by Team CLAC 
	 * Front End Division 11/8/08
	 */
	public class ClassManager extends Accordion
	{
		/* define max number of classes possible */
		private var maxNumClass:int = 6;
		
		/* define color for each class for upto 6 */
		private var color:Array = new Array(0x0600ff, 0x8aff00, 0xffcc00,
		                     				0xff00b4, 0xff0000, 0x9000ff);
		
		/* list of classes and names of that class added to list */
		private var classes   :ArrayList = null;
		private var classNames:ArrayList = null;
		
		/* number of classes in the list above */
		private var numClass:int = 0;
		
		/* Point Mesh object */
		var mesh:PointMesh = null;
		
		/* grid from main */
		var grid:Canvas = null;
		

		
		/**
		 * Constructor
		 */
		public function ClassManager()
		{
			/* initialization */
			numClass = 0;
			classes    = new ArrayList();
			classNames = new ArrayList();
			mesh       = new PointMesh();
			
			/* temporary added classes */
			var tempClass:BlockGenerator;

			tempClass = addClass("Introduction CLAC");
			tempClass.addSection(1,1,2);
			tempClass.addSection(2,5,1);
			
			tempClass = addClass("Intermediate CLAC");
			tempClass.addSection(2,1,1);
			tempClass.addSection(3,6,1);
			
			tempClass = addClass("Advanced CLAC");
			tempClass.addSection(3,1,1);
			tempClass.addSection(4,4,1);
			
			tempClass = addClass("CLAC Capstone1");
			tempClass.addSection(4,1,1);
			tempClass.addSection(5,1,1);
			
			tempClass = addClass("CLAC Elective");
			tempClass.addSection(1,1,1);
			tempClass.addSection(3,1,1);
			
			tempClass = addClass("CLAC Minicourse");
			tempClass.addSection(2,1,1);
			tempClass.addSection(4,1,1);

		}

		/**
		 * Canvas variable from main mxml
		 */
		public function getGrid(tempGrid:Canvas):void {
			grid = tempGrid;
		}

		/**
		 * Add class function
		 */
		private function addClass(title:String):BlockGenerator {
			
			// if max number of class is already reached, stop add
			if(numClass >= maxNumClass)
				return null;

			// create block generator object and add the object and class name to respective list
			var retVal:BlockGenerator = new BlockGenerator(color[numClass], title, this);
			classes   .addItem(retVal);
			classNames.addItem(title);
			
			this.addChild(retVal.getSectionGroup());
			numClass++;
			
			return retVal;
		}
		
		/**
		 * Remove class function
		 */
		private function removeClass(title:String):void {
			
			// if there's no class, stop remove
			if(numClass <= 0)
				return;
				
			// remove class name from class name array list
			var indexClass:int = classNames.getItemIndex(title);
			classNames.removeItemAt(indexClass);
			
			// remove block generator object from array list and do remove child
			var classToRemove:BlockGenerator = BlockGenerator(classes.removeItemAt(indexClass));		
			this.removeChild(classToRemove.getSectionGroup());
			numClass--;
		}

		/**
		 * Function responsible for making, displaying classes box
		
		public function makeBox(evt:MouseEvent):void {
			
			/*
        	var box:UIComponent  = new UIComponent();

        	box.graphics.beginFill(0x1C87C4, 1);
            box.graphics.drawRect( 71, 133, 105, 41 );
            box.graphics.endFill();  
 
            grid.addChild(box);
            
		} */

		/**
		 * Overriden function: dafault function to be loaded
		 */
		protected override function createChildren():void
		{
			super.createChildren();

			for(var i:int = 0; i < numClass; i++) {
				var tempClass:Object = classes.getItemAt(i);
				var currClass:Canvas = tempClass.getSectionGroup();
				
			}
		}
		
	}
}